import axios from '@/libs/api.request'

export const getVillageList = ({ limit, offset }) => {
  return axios.request({
    url: 'village',
    method: 'get',
    params: {
      limit,
      offset
    }
  })
}

export const getVillage = (id) => {
  return axios.request({
    url: `village/${id}`,
    method: 'get'
  })
}

export const getBuilding = (id) => {
  return axios.request({
    url: `building/${id}`,
    method: 'get'
  })
}

export const getBuildingList = (params) => {
  return axios.request({
    url: `building`,
    method: 'get',
    params
  })
}
export const getRoomList = (params) => {
  return axios.request({
    url: `room`,
    method: 'get',
    params
  })
}

export const addBuilding = (data) => {
  return axios.request({
    url: `building`,
    method: 'post',
    data
  })
}

export const addRoom = (data) => {
  return axios.request({
    url: `room`,
    method: 'post',
    data
  })
}

export const addVillage = (data) => {
  return axios.request({
    url: 'village',
    method: 'post',
    data
  })
}

export const deleteVillage = (id) => {
  return axios.request({
    url: `village/${id}`,
    method: 'delete'
  })
}

export const deleteBuilding = (id) => {
  return axios.request({
    url: `building/${id}`,
    method: 'delete'
  })
}
export const deleteRoom = (id) => {
  return axios.request({
    url: `room/${id}`,
    method: 'delete'
  })
}

export const updateVillage = (data) => {
  return axios.request({
    url: `village/${data.id}`,
    method: 'put',
    data
  })
}

export const updateBuilding = (data) => {
  return axios.request({
    url: `building/${data.id}`,
    method: 'put',
    data
  })
}

export const updateRoom = (data) => {
  return axios.request({
    url: `room/${data.id}`,
    method: 'put',
    data
  })
}

export const getTableData = () => {
  return axios.request({
    url: 'get_table_data',
    method: 'get'
  })
}

export const getDragList = () => {
  return axios.request({
    url: 'get_drag_list',
    method: 'get'
  })
}

export const errorReq = () => {
  return axios.request({
    url: 'error_url',
    method: 'post'
  })
}

export const saveErrorLogger = info => {
  return axios.request({
    url: 'save_error_logger',
    data: info,
    method: 'post'
  })
}

export const uploadImg = formData => {
  return axios.request({
    url: 'image/upload',
    data: formData
  })
}

export const getOrgData = () => {
  return axios.request({
    url: 'get_org_data',
    method: 'get'
  })
}

export const getTreeSelectData = () => {
  return axios.request({
    url: 'get_tree_select_data',
    method: 'get'
  })
}
